package tree;

import java.awt.Point;

public class Vector2d {

	public double x, y;

	public Vector2d(double x, double y) {
		this.x = x;
		this.y = y;

	}

	public Vector2d add(Vector2d other) {
		return new Vector2d(x + other.x, y + other.y);
	}

	public Vector2d minus(Vector2d other) {
		return new Vector2d(x - other.x, y - other.y);
	}

	public Vector2d mult(Vector2d other) {
		return new Vector2d(x * other.x, y * other.y);
	}

	public Vector2d div(Vector2d other) {
		return new Vector2d(x / other.x, y / other.y);
	}

	public Vector2d add(double other) {
		return new Vector2d(x + other, y + other);
	}

	public Vector2d minus(double other) {
		return new Vector2d(x - other, y - other);
	}

	public Vector2d mult(double other) {
		return new Vector2d(x * other, y * other);
	}

	public Vector2d div(double other) {
		return new Vector2d(x / other, y / other);
	}

	public void Normalize() {
		double Norm = 1 / (Math.sqrt((x) * (x) + (y) * (y)));
		x *= Norm;
		y *= Norm;
	}
	
	public TreePoint toPoint(){
		return new TreePoint((int)Math.round(x),(int)Math.round(y),0);
		
	}
	
	public static Vector2d randomVector(){
		Vector2d rand = new Vector2d(Math.random() - 0.5,Math.random() - 0.5);
		rand.Normalize();
		return rand;
	}
	

	public double dot(Vector2d other) {
		return (x * other.x) + (y * other.y);
	}

}
